package com.jml.装饰模式.五期.异步多渠道群发框架.service;


import com.alibaba.fastjson.JSONObject;
import com.jml.装饰模式.五期.异步多渠道群发框架.entity.UserMessageEntity;
import com.jml.装饰模式.五期.异步多渠道群发框架.observer.JmlSubject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class OrderService {


    @Autowired
    private JmlSubject jmlSubject;
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;
    @RequestMapping("/addOrder")
    public String addOrder() {
        log.info("1.调用数据库下单订单代码:");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("sms", "1865891111");
        jsonObject.put("email", "644064779@qq.com");
        jmlSubject.notifyObServer(jsonObject);
        return "success";
    }



    @RequestMapping("/addOrder2")
    public String addOrder2() {
        log.info("1.调用数据库下单订单代码:");
        UserMessageEntity userMessageEntity = new UserMessageEntity(
                this, "644064779@qq.com", "1865891111");
        applicationEventPublisher.publishEvent(userMessageEntity);
        return "success";
    }

}
